
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.3 了解 Docker 网络 · Kubernetes - 痴者工良</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="痴者工良">
        
        
    
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.pod_docker.html" />
    
    
    <link rel="prev" href="2.virtual.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.whuanle.cn" target="_blank" class="custom-link">痴者工良的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    文档说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    1.基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="./">
            
                <a href="./">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="1.docker.html">
            
                <a href="1.docker.html">
            
                    
                    1.1 说透 Docker：基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="2.virtual.html">
            
                <a href="2.virtual.html">
            
                    
                    1.2 说透 Docker： 虚拟化
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.4" data-path="3.docker_network.html">
            
                <a href="3.docker_network.html">
            
                    
                    1.3 了解 Docker 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="4.pod_docker.html">
            
                <a href="4.pod_docker.html">
            
                    
                    1.4 Docker 和 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="5.k8s.html">
            
                <a href="5.k8s.html">
            
                    
                    1.5 K8S入门基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../2.deploy/">
            
                <a href="../2.deploy/">
            
                    
                    2.部署和配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../2.deploy/2.deploy.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../2.deploy/1.minikube.html">
            
                <a href="../2.deploy/1.minikube.html">
            
                    
                    2.1 使用 Minikube 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../2.deploy/2.kubeadm.html">
            
                <a href="../2.deploy/2.kubeadm.html">
            
                    
                    2.2 使用 kubeadm 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../2.deploy/3.kubeadm_ckad.html">
            
                <a href="../2.deploy/3.kubeadm_ckad.html">
            
                    
                    2.3 CKAD认证中的部署教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../2.deploy/4.kubeadm_proxy.html">
            
                <a href="../2.deploy/4.kubeadm_proxy.html">
            
                    
                    2.4 国内代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../2.deploy/5.dashboard.html">
            
                <a href="../2.deploy/5.dashboard.html">
            
                    
                    2.5 Dashboard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    3.Pod部署和调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../3.pod/1.pod.html">
            
                <a href="../3.pod/1.pod.html">
            
                    
                    3.1 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../3.pod/2.deployment.html">
            
                <a href="../3.pod/2.deployment.html">
            
                    
                    3.2 Deployment部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../3.pod/3.replica.html">
            
                <a href="../3.pod/3.replica.html">
            
                    
                    3.3 副本集(ReplicaSet)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../3.pod/4.pod_network.html">
            
                <a href="../3.pod/4.pod_network.html">
            
                    
                    3.34 Pod 端口映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../3.pod/5.update.html">
            
                <a href="../3.pod/5.update.html">
            
                    
                    3.5 Pod 升级、回滚
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../3.pod/6.scale.html">
            
                <a href="../3.pod/6.scale.html">
            
                    
                    3.6 Pod 缩放
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../3.pod/7.lable.html">
            
                <a href="../3.pod/7.lable.html">
            
                    
                    3.7.Pod 标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../3.pod/8.schedule.html">
            
                <a href="../3.pod/8.schedule.html">
            
                    
                    3.8 Pod 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../3.pod/9.jobs_cronjobs.html">
            
                <a href="../3.pod/9.jobs_cronjobs.html">
            
                    
                    3.9 Jobs、CronJobs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../4.network/">
            
                <a href="../4.network/">
            
                    
                    4.Kubernetes 网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../4.network/">
            
                <a href="../4.network/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../4.network/1.network.html">
            
                <a href="../4.network/1.network.html">
            
                    
                    4.1 Kubernetes 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../4.network/2.endpoint.html">
            
                <a href="../4.network/2.endpoint.html">
            
                    
                    4.2 Endpoint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../4.network/3.ingress.html">
            
                <a href="../4.network/3.ingress.html">
            
                    
                    4.3 ingress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../4.network/4.discovery.html">
            
                <a href="../4.network/4.discovery.html">
            
                    
                    4.4 服务发现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    5.volumes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../5.volumes/1.volumes.html">
            
                <a href="../5.volumes/1.volumes.html">
            
                    
                    5.1 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../5.volumes/2.secret_configmap.html">
            
                <a href="../5.volumes/2.secret_configmap.html">
            
                    
                    5.2 secret 和 ConfigMap 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../5.volumes/3.nfts.html">
            
                <a href="../5.volumes/3.nfts.html">
            
                    
                    5.3 NFS卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../5.volumes/4.pv_pvc.html">
            
                <a href="../5.volumes/4.pv_pvc.html">
            
                    
                    5.4 持久化卷
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    6.API 和 安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../7.health/">
            
                <a href="../7.health/">
            
                    
                    7.维护和故障排除
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../8.health/README.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../k8s.html">
            
                <a href="../k8s.html">
            
                    
                    Kubernetes 命令概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../ckad.html">
            
                <a href="../ckad.html">
            
                    
                    CKAD 认证帮助
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1.3 了解 Docker 网络</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#13-&#x4E86;&#x89E3;-docker-&#x7F51;&#x7EDC;"><b></b>1.3 &#x4E86;&#x89E3; Docker &#x7F51;&#x7EDC;</a></li><ul><li><span class="title-icon "></span><a href="#docker-&#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;"><b></b>Docker &#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;</a></li><ul><li><span class="title-icon "></span><a href="#bridge-&#x6A21;&#x5F0F;"><b></b>bridge &#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#none-&#x6A21;&#x5F0F;"><b></b>none &#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#host-&#x6A21;&#x5F0F;"><b></b>host &#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#container-&#x6A21;&#x5F0F;"><b></b>container &#x6A21;&#x5F0F;</a></li></ul></ul></ul></div><h1 id="13-&#x4E86;&#x89E3;-docker-&#x7F51;&#x7EDC;"><a name="13-&#x4E86;&#x89E3;-docker-&#x7F51;&#x7EDC;" class="anchor-navigation-ex-anchor" href="#13-&#x4E86;&#x89E3;-docker-&#x7F51;&#x7EDC;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3 &#x4E86;&#x89E3; Docker &#x7F51;&#x7EDC;</h1>
<p>&#x672C;&#x7AE0;&#x5C06;&#x4F1A;&#x7B80;&#x5355;&#x5730;&#x8BB2;&#x8FF0; Docker &#x4E2D;&#x7684;&#x7F51;&#x7EDC;&#xFF0C;&#x5BF9;&#x4E8E; CNM&#x3001;Libnetwork &#x8FD9;&#x4E9B;&#xFF0C;&#x9650;&#x4E8E;&#x7B14;&#x8005;&#x4E2A;&#x4EBA;&#x6C34;&#x5E73;&#xFF0C;&#x5C06;&#x4E0D;&#x4F1A;&#x5305;&#x542B;&#x5728;&#x5185;&#x3002;</p>
<h2 id="docker-&#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;"><a name="docker-&#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#docker-&#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>Docker &#x7684;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;</h2>
<p>Docker &#x6709; bridge&#x3001;none&#x3001;host&#x3001;container &#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#xFF0C;&#x63D0;&#x4F9B;&#x7F51;&#x7EDC;&#x9694;&#x79BB;&#x3001;&#x7AEF;&#x53E3;&#x6620;&#x5C04;&#x3001;&#x5BB9;&#x5668;&#x95F4;&#x4E92;&#x901A;&#x7F51;&#x7EDC;&#x7B49;&#x5404;&#x79CD;&#x652F;&#x6301;&#xFF0C;&#x4E0B;&#x9762;&#x5F00;&#x95E8;&#x89C1;&#x5C71;&#x5730;&#x76F4;&#x63A5;&#x4ECB;&#x7ECD;&#x8FD9;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#x3002;</p>
<p>&#x8FD9;&#x56DB;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x542F;&#x52A8;&#x5BB9;&#x5668;&#x7684;&#x65F6;&#x5019;&#x6307;&#x5B9A;&#xFF0C;&#x5176;&#x547D;&#x4EE4;&#x6216;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x5982;&#x4E0B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;</th>
<th>&#x53C2;&#x6570;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>host&#x6A21;&#x5F0F;</td>
<td>-&#x2013;net=host</td>
<td>&#x5BB9;&#x5668;&#x548C;&#x5BBF;&#x4E3B;&#x673A;&#x5171;&#x4EAB; Network namespace&#x3002;</td>
</tr>
<tr>
<td>container&#x6A21;&#x5F0F;</td>
<td>&#x2013;-net={id}</td>
<td>&#x5BB9;&#x5668;&#x548C;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x5171;&#x4EAB; Network namespace&#x3002; kubernetes &#x4E2D;&#x7684;pod&#x5C31;&#x662F;&#x591A;&#x4E2A;&#x5BB9;&#x5668;&#x5171;&#x4EAB;&#x4E00;&#x4E2A; Network namespace&#x3002;</td>
</tr>
<tr>
<td>none&#x6A21;&#x5F0F;</td>
<td>&#x2013;-net=none</td>
<td>&#x5BB9;&#x5668;&#x6709;&#x72EC;&#x7ACB;&#x7684;Network namespace&#xFF0C;&#x4F46;&#x5E76;&#x6CA1;&#x6709;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x7F51;&#x7EDC;&#x8BBE;&#x7F6E;&#xFF0C;&#x5982;&#x5206;&#x914D; veth pair &#x548C;&#x7F51;&#x6865;&#x8FDE;&#x63A5;&#xFF0C;&#x914D;&#x7F6E;IP&#x7B49;&#x3002;</td>
</tr>
<tr>
<td>bridge&#x6A21;&#x5F0F;</td>
<td>-&#x2013;net=bridge</td>
<td>&#x9ED8;&#x8BA4;&#x4E3A;&#x8BE5;&#x6A21;&#x5F0F;&#xFF0C;&#x901A;&#x8FC7; -p &#x6307;&#x5B9A;&#x7AEF;&#x53E3;&#x6620;&#x5C04;&#x3002;</td>
</tr>
</tbody>
</table>
<p>&#x8FD9;&#x56DB;&#x79CD;&#x6A21;&#x5F0F;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x6210; Docker &#x600E;&#x4E48;&#x865A;&#x62DF;&#x5316;&#x5BB9;&#x5668;&#x7684;&#x7F51;&#x7EDC;&#xFF0C;&#x9694;&#x79BB;&#x7A0B;&#x5EA6;&#x548C;&#x5171;&#x4EAB;&#x7A0B;&#x5EA6;&#x3002;</p>
<h3 id="bridge-&#x6A21;&#x5F0F;"><a name="bridge-&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#bridge-&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>bridge &#x6A21;&#x5F0F;</h3>
<p>&#x4F7F;&#x7528; Docker &#x521B;&#x5EFA;&#x4E00;&#x4E2A; bridge &#x6A21;&#x5F0F;&#x7684;&#x5BB9;&#x5668;&#x547D;&#x4EE4;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-shell">docker run -itd -p <span class="token number">8080</span>:80 nginx:latest
</code></pre>
<p>bridge &#x6A21;&#x5F0F;&#x79F0;&#x4E3A;&#x7F51;&#x6865;&#x6A21;&#x5F0F;&#xFF0C;&#x9996;&#x5148; Docker &#x4F1A;&#x5728;&#x4E3B;&#x673A;&#x4E0A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; docker0 &#x7684;&#x865A;&#x62DF;&#x7F51;&#x6865;&#xFF0C;&#x8FD9;&#x4E2A;&#x865A;&#x62DF;&#x7F51;&#x7EDC;&#x5904;&#x4E8E;&#x4E03;&#x5C42;&#x7F51;&#x7EDC;&#x6A21;&#x578B;&#x7684;&#x6570;&#x636E;&#x94FE;&#x8DEF;&#x5C42;&#xFF0C;&#x6BCF;&#x5F53;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5BB9;&#x5668;&#x65F6;&#xFF0C;&#x5BB9;&#x5668;&#x90FD;&#x4F1A;&#x901A;&#x8FC7; docker0 &#x4E0E;&#x4E3B;&#x673A;&#x7684;&#x7F51;&#x7EDC;&#x8FDE;&#x63A5;&#xFF0C;docker0 &#x76F8;&#x5F53;&#x4E8E;&#x7F51;&#x6865;&#x3002;</p>
<p>&#x4F7F;&#x7528; bridge &#x6A21;&#x5F0F;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x5176;&#x5185;&#x90E8;&#x90FD;&#x6709;&#x4E00;&#x4E2A;&#x865A;&#x62DF;&#x7F51;&#x5361;&#xFF0C;&#x540D;&#x4E3A; eth0&#xFF0C;&#x5BB9;&#x5668;&#x4E4B;&#x95F4;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; 172.17.x.x &#x76F8;&#x4E92;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7F51;&#x6865;&#x9ED8;&#x8BA4; IP &#x8303;&#x56F4;&#x662F; 172.17.x.x &#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x5BBF;&#x4E3B;&#x673A;&#x6267;&#x884C; ifpconfig &#x547D;&#x4EE4;&#x67E5;&#x770B;&#x6240;&#x6709;&#x7F51;&#x5361;&#xFF0C;&#x91CC;&#x9762;&#x4F1A;&#x5305;&#x542B; Docker  &#x5BB9;&#x5668;&#x7684;&#x865A;&#x62DF;&#x7F51;&#x5361;&#xFF0C;&#x53EF;&#x4EE5;&#x67E5;&#x770B;&#x67D0;&#x4E2A;&#x5BB9;&#x5668;&#x7684; ip&#x3002;&#x5728;&#x5BB9;&#x5668;&#x4E2D;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; ifconfig &#x547D;&#x4EE4;&#x67E5;&#x770B;&#x81EA;&#x8EAB;&#x7684;&#x5BB9;&#x5668; ip&#xFF1A;</p>
<pre class="language-"><code class="lang-shell">root@cda6958393cb:/var<span class="token comment"># ./ifconfig </span>
eth0: <span class="token assign-left variable">flags</span><span class="token operator">=</span><span class="token number">416</span><span class="token operator"><span class="token file-descriptor important">3</span>&lt;</span>UP,BROADCAST,RUNNING,MULTICAST<span class="token operator">&gt;</span>  mtu <span class="token number">1500</span>
        inet <span class="token number">172.17</span>.0.2  netmask <span class="token number">255.255</span>.0.0  broadcast <span class="token number">172.17</span>.255.255
        ether 02:42:ac:11:00:02  txqueuelen <span class="token number">0</span>  <span class="token punctuation">(</span>Ethernet<span class="token punctuation">)</span>
        RX packets <span class="token number">347</span>  bytes <span class="token number">9507996</span> <span class="token punctuation">(</span><span class="token number">9.5</span> MB<span class="token punctuation">)</span>
        RX errors <span class="token number">0</span>  dropped <span class="token number">0</span>  overruns <span class="token number">0</span>  frame <span class="token number">0</span>
        TX packets <span class="token number">278</span>  bytes <span class="token number">22384</span> <span class="token punctuation">(</span><span class="token number">22.3</span> KB<span class="token punctuation">)</span>
        TX errors <span class="token number">0</span>  dropped <span class="token number">0</span> overruns <span class="token number">0</span>  carrier <span class="token number">0</span>  collisions <span class="token number">0</span>

lo: <span class="token assign-left variable">flags</span><span class="token operator">=</span><span class="token number">7</span><span class="token operator"><span class="token file-descriptor important">3</span>&lt;</span>UP,LOOPBACK,RUNNING<span class="token operator">&gt;</span>  mtu <span class="token number">65536</span>
        inet <span class="token number">127.0</span>.0.1  netmask <span class="token number">255.0</span>.0.0
        loop  txqueuelen <span class="token number">1000</span>  <span class="token punctuation">(</span>Local Loopback<span class="token punctuation">)</span>
        RX packets <span class="token number">0</span>  bytes <span class="token number">0</span> <span class="token punctuation">(</span><span class="token number">0.0</span> B<span class="token punctuation">)</span>
        RX errors <span class="token number">0</span>  dropped <span class="token number">0</span>  overruns <span class="token number">0</span>  frame <span class="token number">0</span>
        TX packets <span class="token number">0</span>  bytes <span class="token number">0</span> <span class="token punctuation">(</span><span class="token number">0.0</span> B<span class="token punctuation">)</span>
        TX errors <span class="token number">0</span>  dropped <span class="token number">0</span> overruns <span class="token number">0</span>  carrier <span class="token number">0</span>  collisions <span class="token number">0</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x6B64;&#x5BB9;&#x5668;&#x7684; ip &#x662F; 172.17.0.2&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x4E86; bride &#x521B;&#x5EFA;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x5176;&#x7F51;&#x7EDC;&#x4E0E;&#x4E3B;&#x673A;&#x4EE5;&#x53CA;&#x5176;&#x4ED6;&#x5BB9;&#x5668;&#x9694;&#x79BB;&#xFF0C;&#x4EE5;&#x592A;&#x7F51;&#x63A5;&#x53E3;&#x3001;&#x7AEF;&#x53E3;&#x3001;&#x8DEF;&#x7531;&#x8868;&#x4EE5;&#x53CA; DNS&#x914D;&#x7F6E; &#x90FD;&#x662F;&#x72EC;&#x7ACB;&#x7684;&#x3002;&#x6BCF;&#x4E2A;&#x5BB9;&#x5668;&#x90FD;&#x597D;&#x50CF;&#x662F;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x4E3B;&#x673A; &#xFF0C;&#x8FD9;&#x4FBF;&#x662F; bridge&#xFF08;&#x7F51;&#x6865;&#xFF09;&#x7684;&#x4F5C;&#x7528;&#x3002;&#x4F46;&#x662F;&#x56E0;&#x4E3A; docker0 &#x7684;&#x5B58;&#x5728;&#xFF0C;&#x5BF9;&#x4E8E;&#x5BB9;&#x5668;&#x6765;&#x8BF4;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; ip &#x8BBF;&#x95EE;&#x522B;&#x7684;&#x5BB9;&#x5668;&#x3002;</p>
<p><img src="images/docker_bridge.png" alt="docker_bridge"></p>
<p>&#x5BB9;&#x5668;1 &#x53EF;&#x4EE5;&#x901A;&#x8FC7; 172.17.0.3 &#x8BBF;&#x95EE;&#x5BB9;&#x5668;2&#xFF0C;&#x540C;&#x6837;&#xFF0C;&#x4E3B;&#x673A;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A; ip &#x8BBF;&#x95EE;&#x5BB9;&#x5668;2 &#x4E2D;&#x7684;&#x670D;&#x52A1;&#x3002;</p>
<blockquote>
<p><strong>[Error] &#x63D0;&#x793A;</strong></p>
<p>bridge &#x6A21;&#x5F0F; &#x662F;&#x9ED8;&#x8BA4;&#x6A21;&#x5F0F;&#xFF0C;&#x5373;&#x4F7F;&#x662F; &#x4F7F;&#x7528; <code>docker run -itd  nginx:latest</code> &#x547D;&#x4EE4;&#x542F;&#x52A8;&#x5BB9;&#x5668;&#xFF0C;&#x4E5F;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x865A;&#x62DF; IP&#x3002;</p>
</blockquote>
<h3 id="none-&#x6A21;&#x5F0F;"><a name="none-&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#none-&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>none &#x6A21;&#x5F0F;</h3>
<p>&#x8FD9;&#x79CD;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#x4E0B;&#x5BB9;&#x5668;&#x53EA;&#x6709; lo &#x56DE;&#x73AF;&#x7F51;&#x7EDC;&#xFF0C;&#x6CA1;&#x6709;&#x5176;&#x4ED6;&#x7F51;&#x5361;&#xFF0C;&#x8FD9;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x7F51;&#x7EDC;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x8054;&#x7F51;&#xFF0C;&#x5916;&#x754C;&#x4E5F;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;&#x5B83;&#xFF0C;&#x5C01;&#x95ED;&#x7684;&#x7F51;&#x7EDC;&#x80FD;&#x5F88;&#x597D;&#x5730;&#x4FDD;&#x8BC1;&#x5BB9;&#x5668;&#x7684;&#x5B89;&#x5168;&#x6027;&#x3002;</p>
<p>&#x521B;&#x5EFA; none &#x7F51;&#x7EDC;&#x7684;&#x5BB9;&#x5668;&#xFF1A;</p>
<pre class="language-"><code class="lang-shell">docker run -itd --net<span class="token operator">=</span>none nginx:latest
</code></pre>
<pre class="language-"><code>root@5a67da130f62:/var# ./ifconfig 
lo: flags=73<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>UP,LOOPBACK,RUNNING</span><span class="token punctuation">&gt;</span></span>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
</code></pre><p><img src="images/docker_none.png" alt="docker_none"></p>
<h3 id="host-&#x6A21;&#x5F0F;"><a name="host-&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#host-&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>host &#x6A21;&#x5F0F;</h3>
<p>host &#x6A21;&#x5F0F;&#x4F1A;&#x8BA9;&#x5BB9;&#x5668;&#x4E0E;&#x4E3B;&#x673A;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#xFF0C;&#x6B64;&#x65F6;&#x6620;&#x5C04;&#x7684;&#x7AEF;&#x53E3;&#x53EF;&#x80FD;&#x4F1A;&#x751F;&#x4EA7;&#x51B2;&#x7A81;&#xFF0C;&#x4F46;&#x662F;&#x5BB9;&#x5668;&#x7684;&#x5176;&#x4F59;&#x90E8;&#x5206;(&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x3001;&#x8FDB;&#x7A0B;&#x7B49;)&#x4F9D;&#x7136;&#x662F;&#x9694;&#x79BB;&#x7684;&#xFF0C;&#x6B64;&#x65F6;&#x5BB9;&#x5668;&#x4E0E;&#x5BBF;&#x4E3B;&#x673A;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#x3002;</p>
<p><img src="images/docker_host.png" alt="docker_host"></p>
<h3 id="container-&#x6A21;&#x5F0F;"><a name="container-&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#container-&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>container &#x6A21;&#x5F0F;</h3>
<p>container &#x6A21;&#x5F0F;&#x53EF;&#x4EE5;&#x8BA9;&#x591A;&#x4E2A;&#x5BB9;&#x5668;&#x4E4B;&#x95F4;&#x76F8;&#x4E92;&#x901A;&#x8BAF;&#xFF0C;&#x5373;&#x5BB9;&#x5668;&#x4E4B;&#x95F4;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#x3002;</p>
<p>&#x9996;&#x5148;&#x542F;&#x52A8;&#x4E00;&#x4E2A; A &#x5BB9;&#x5668;&#xFF0C;A &#x4E00;&#x822C;&#x4E3A; bridge &#x7F51;&#x7EDC;&#xFF0C;&#x63A5;&#x7740; B &#x4F7F;&#x7528; <code>&#x2013;-net={id}</code> &#x8FDE;&#x63A5;&#x5230; A &#x4E2D;&#xFF0C;&#x4F7F;&#x7528; A &#x7684;&#x865A;&#x62DF;&#x7F51;&#x5361;&#xFF0C;&#x6B64;&#x65F6; A&#x3001;B &#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#xFF0C;&#x53EF;&#x4EE5;&#x63A5;&#x7740;&#x52A0;&#x5165; B&#x3001;C&#x3001;D &#x7B49;&#x5BB9;&#x5668;&#x3002;</p>
<p><img src="images/docker_network_container.jpg" alt="docker_network_container"></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x75F4;&#x8005;&#x5DE5;&#x826F; 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x6863;&#x6700;&#x540E;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2021-11-17 07:16:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2.virtual.html" class="navigation navigation-prev " aria-label="Previous page: 1.2 说透 Docker： 虚拟化">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.pod_docker.html" class="navigation navigation-next " aria-label="Next page: 1.4 Docker 和 Pod">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.3 了解 Docker 网络","level":"1.2.4","depth":2,"next":{"title":"1.4 Docker 和 Pod","level":"1.2.5","depth":2,"path":"1.basic/4.pod_docker.md","ref":"1.basic/4.pod_docker.md","articles":[]},"previous":{"title":"1.2 说透 Docker： 虚拟化","level":"1.2.3","depth":2,"path":"1.basic/2.virtual.md","ref":"1.basic/2.virtual.md","articles":[]},"dir":"ltr"},"config":{"plugins":["tbfed-pagefooter","anchor-navigation-ex","mermaid-gb3","insert-logo","chapter-fold","advanced-emoji","github","splitter","alerts","popup","prism","-highlight","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 痴者工良 2021","modify_label":"文档最后更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"prism":{"lang":{"flow":"typescript","shell":"bash"},"ignore":["mermaid","eval-js"],"css":["prismjs/themes/prism.css"],"js":["prismjs/prism.js","prismjs/components.js","prismjs/components/prism-go.min.js","prismjs/components/prism-yaml.min.js","prismjs/components/prism-bash.min.js","prismjs/components/prism-shell-session.min.js"]},"github":{"url":"https://github.com/whuanle/kubernetes"},"livereload":{},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"alerts":{},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"/images/logo.jpg"}},"theme":"default","author":"痴者工良","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Kubernetes - 痴者工良","language":"zh-hans","links":{"sidebar":{"痴者工良的博客":"https://www.whuanle.cn"}},"gitbook":"*","description":"这是一本关于 Kubernetes 的书，作者 痴者工良"},"file":{"path":"1.basic/3.docker_network.md","mtime":"2021-11-16T23:16:53.004Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-16T23:21:22.294Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

